﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;

namespace Kokomo.Environment.Documents
{
	public class NavigationView : ContentControl
	{
		static NavigationView()
		{
			DefaultStyleKeyProperty.OverrideMetadata(typeof(NavigationView), new FrameworkPropertyMetadata(typeof(NavigationView)));
		}

		public ICommand GoBackCommand
		{
			get { return (ICommand)GetValue(GoBackCommandProperty); }
			set { SetValue(GoBackCommandProperty, value); }
		}

		// Using a DependencyProperty as the backing store for GoBackCommand.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty GoBackCommandProperty =
			DependencyProperty.Register("GoBackCommand", typeof(ICommand), typeof(NavigationView), new UIPropertyMetadata(null));



		public ICommand GoForwardCommand
		{
			get { return (ICommand)GetValue(GoForwardCommandProperty); }
			set { SetValue(GoForwardCommandProperty, value); }
		}

		// Using a DependencyProperty as the backing store for GoForwardCommand.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty GoForwardCommandProperty =
			DependencyProperty.Register("GoForwardCommand", typeof(ICommand), typeof(NavigationView), new UIPropertyMetadata(null));



		protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e)
		{
			if (
				(e.Key == Key.Back)
				|| (e.Key == Key.BrowserBack)
				|| (e.SystemKey == Key.Left)
				)
			{
				if (
					this.GoBackCommand != null
					&& this.GoBackCommand.CanExecute(null)
					)
				{
					this.GoBackCommand.Execute(null);
					e.Handled = true;
				}
			}
			else if (
			  (e.Key == Key.BrowserForward)
			  || (e.SystemKey == Key.Right)
			  )
			{
				if (
					(this.GoForwardCommand != null)
					&& this.GoForwardCommand.CanExecute(null)
					)
				{
					this.GoForwardCommand.Execute(null);
					e.Handled = true;
				}
			}

			base.OnKeyDown(e);
		}
	}
}
